package com.pay.manager.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pay.manager.dao.BaseAdminUserMapper;
import com.pay.manager.dao.UserMapper;
import com.pay.manager.dto.UserInfoSearchDTO;
import com.pay.manager.pojo.BaseAdminUser;
import com.pay.manager.pojo.User;
import com.pay.manager.response.PageDataResult;
import com.pay.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @Title: UserServiceImpl
 * @Description:
 * @author: yjw
 * @version: 1.0
 * @date: 2020/6/12 11:04
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
	
	@Autowired
	private UserMapper userDao;
	
	 @Override
	    public PageDataResult getUserList(UserInfoSearchDTO userinfoSearch, Integer pageNum, Integer pageSize) {
	        PageDataResult pageDataResult = new PageDataResult();
	        System.out.println(userinfoSearch);
	        List<User> users = userDao.getUserList(userinfoSearch);

	        PageHelper.startPage(pageNum, pageSize);

	        if(users.size() != 0){
	            PageInfo<User> pageInfo = new PageInfo<>(users);
	            pageDataResult.setList(users);
	            pageDataResult.setTotals((int) pageInfo.getTotal());
	        }

	        return pageDataResult;
	    }
	 
	 @Override
	    public Map<String,Object> delete(String uname,String operationPwd) {
	        Map<String,Object> data = new HashMap();
	        System.out.println(uname);
	        System.out.println(operationPwd);
	        	if(operationPwd.equals("123456")) {
	        		User user = userDao.selectByName(uname);
	        		userDao.deleteByPrimaryKey(user.getId().intValue());
	        		data.put("code",1);
		            data.put("msg","删除成功！");
	        	}else {
	        		data.put("code",0);
	                data.put("msg","操作密码有误！");
	                return data;
	        	}
	        return data;
	    }
}
